/**
 * 
 */
package com.gr.staffpm.widget.calendar;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.RepeatingView;

import com.gr.staffpm.widget.calendar.event.EventPanel;


/**
 * @author Graham Rhodes 6 Jan 2011 19:02:39
 */
public class MonthRow extends Panel {

    private static final long serialVersionUID = 1L;
    private final java.util.Calendar cal = java.util.Calendar.getInstance();

    public MonthRow(String id, java.util.Calendar calRef, final int month) {
        super(id);

        cal.setTime(calRef.getTime());
        calRef.add(java.util.Calendar.DAY_OF_MONTH, 7);

        //Get list of dates in week specified and add them to the panel
        RepeatingView monthDates = new RepeatingView("monthDates");
        RepeatingView monthEventDays = new RepeatingView("monthEventDays");
        while (cal.getTime().before(calRef.getTime())) {
            final String date = String.valueOf(cal.get(java.util.Calendar.DAY_OF_MONTH));

            if (cal.get(java.util.Calendar.DATE) == 1)
                monthDates.add(new MonthLabel(date, cal, month, true));
            else
                monthDates.add(new MonthLabel(date, cal, month));
            monthEventDays.add(new EventPanel(date, cal));
            cal.add(java.util.Calendar.DATE, 1);
        }
        add(monthDates);
        add(monthEventDays);

    }

    @Override
    protected void onComponentTag(ComponentTag tag) {
        super.onComponentTag(tag);
        tag.getAttributes().put("style", "top: " + Calendar.getMonthRowCurrentTop() + "%; height: " + Calendar.getMonthRowHeight() + "%;");
        Calendar.setMonthRowCurrentTop(Calendar.getMonthRowCurrentTop() + Calendar.getMonthRowHeight());
    }

}
